<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>

<body>
    <script>
        // axios是一个函数 默认是get请求
        // axios是基于promise和XMLHttpRequset的
        
        // 请求拦截器
        axios.interceptors.request.use((config) => {
            console.log("请求拦截信息", config);
            return config;
        })
        // 响应拦截器
        axios.interceptors.response.use(response => {
            console.log("响应拦截成功的回调", response.data);
            return response.data;
        }, error => {
            console.log("响应拦截失败");
            throw error;
        })

        axios('https://api.github.com/search/users?q=a')
            .then(data => {
                console.log('成功了',data);
            }, error => {
                console.log('失败了', error.message);
            })
        console.log("已发送请求");
    </script>
</body>

</html>